import axios from 'axios';
import Nprogress from 'nprogress'
import { message } from 'antd'
import { TOKEN } from '../constan';
// const baseURL = "https://www.liulongbin.top:8888/api/private/v1/"
const baseURL = "http://timemeetyou.com:8889/api/private/v1/"
//const baseURL = "/api/private/v1/"


const request = axios.create({
  baseURL,
})


request.interceptors.request.use(config => {
  Nprogress.start()
  const user = JSON.parse(localStorage.getItem(TOKEN) || '{}')
  if (user.token) {
    config.headers.Authorization = user.token
  }

  return config
})
request.interceptors.response.use(config => {

  Nprogress.done()
  Nprogress.remove()
  const { data } = config
  if (data.meta.status !== 200) {
    message.error({
      content: data.meta.msg
    })

    return null
  }
  message.success({
    content: data.meta.msg
  })
  return data.data
})

export default request